const { db, query } = require("../../db/db");
const util = require("util");

async function GetLabelList(req, res) {
  let PageSize = req.body.PageSize;
  let PageNum = req.body.PageNum;

  if (!PageSize) {
    PageSize = 30;
  }
  if (!PageNum) {
    PageNum = 1;
  }

  const select_GetLabelList_list_sql = util.format(
    "Select \
    LabelId, \
    IFNULL(LavbelName,'') as LavbelName \
    From Label\
    Limit %s,%s",
    (PageNum - 1) * PageSize,
    PageSize
  );

  const select_GetLabelList_list_res = await query(
    select_GetLabelList_list_sql
  );

  //获取总数

  const select_sql_all = util.format(
    "Select count(LabelId) as TotalCount FROM Label"
  );

  const select_sql_all_res = await query(select_sql_all);

  res.send({
    status: 0,
    LabelList: select_GetLabelList_list_res,
    TotalCount: select_sql_all_res[0].TotalCount,
  });
}

module.exports = { GetLabelList };
